package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.DataOverViewQueryDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.*;

import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Mapper
public interface orderMapper {

    /**
     * 插入数据
     * @param order
     * @return
     */
    void save(Orders order);
    @Select("select * from orders where id=#{id}")
    Orders findById(Integer id);

    void insertOrderDetail(List<OrderDetail> list);

    @Select("select * from orders where user_id=#{currentId}")
    Page<Orders> getAll(Long currentId);

    @Update("update orders set status=6")
    void updateOrderStatus(Long id);
    /**
     * 根据订单号查询订单
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    @Select("select * from order_detail where order_id=#{orderNumber}")
    List<OrderDetail> getListOrderDetailByOrderId(String orderNumber);
    Page<Orders> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);


    /**
     * 订单状态统计
     */
    @Select(" SELECT status, COUNT(*) AS count\n" +
            "        FROM orders\n" +
            "        WHERE status IN ('1', '3', '4')\n" +
            "        GROUP BY status;")
    List<Map<String, Object>> statistics();

    /**
     * 更新订单状态
     */
    @Update(" update orders set\n" +
            "            status = 3 where id = #{id}")
    void updateStatus(OrdersConfirmDTO ordersConfirmDTO);


    @MapKey("name")
   List<Map<String,Object>> selectTop10(@Param("collect") Set<BigInteger> collect);
}



